Skip to main content

stdint.h

# Fixed-width integer types

stdint.h defines a number of fixed-width integer type aliases, the three main types being the following.

  • Integers with a completely determined width intN_t, e.g. int32_t.
  • Integers of width not less than a certain size int_leastN_t, e.g. int_least8_t.
  • An integer int_fastN_t whose width is not less than a certain size and which is processed as fast as possible, e.g. int_fast64_t.

All the above types are signed, and the type name may be preceded by a prefix u to indicate an unsigned type, e.g. uint16_t.

The C language standard requires the following types to be defined.

  • int8_t (optional) uint8_t (optional)
  • int16_t (optional) uint16_t (optional)
  • int32_t (optional) uint32_t (optional)
  • int64_t (optional) uint64_t (optional)
  • int_least8_t uint_least8_t
  • int_least16_t uint_least16_t
  • int_least32_t uint_least32_t
  • int_least64_t uint_least64_t
  • int_fast8_t uint_fast8_t
  • int_fast16_t uint_fast16_t
  • int_fast32_t uint_fast32_t
  • int_fast64_t uint_fast64_t

Maximum width integer types

The following two types represent the maximum width integers currently available to the system.

  • intmax_t
  • uintmax_t

The above types can be used if the largest possible integer is desired.

Fixed-width integer constants

Some of the following macros with parameters can generate fixed-width integer constants.

  • INT8_C(x) UINT8_C(x)
  • INT16_C(x) UINT16_C(x)
  • INT32_C(x) UINT32_C(x)
  • INT64_C(x) UINT64_C(x)
  • INTMAX_C(x) UINTMAX_C(x)

Here is an example of usage.

uint16_t x = UINT16_C(12);
intmax_t y = INTMAX_C(3490);

Fixed-width integer limit values

Some of the following macros represent the maximum and minimum integer values for fixed widths.

  • INT8_MAX INT8_MIN UINT8_MAX
  • INT16_MAX INT16_MIN UINT16_MAX
  • INT32_MAX INT32_MIN UINT32_MAX
  • int64_max int64_min uint64_max
  • int_least8_max int_least8_min uint_least8_max
  • INT_LEAST16_MAX INT_LEAST16_MIN UINT_LEAST16_MAX
  • INT_LEAST32_MAX INT_LEAST32_MIN UINT_LEAST32_MAX
  • INT_LEAST64_MAX INT_LEAST64_MIN UINT_LEAST64_MAX
  • int_fast8_max int_fast8_min uint_fast8_max
  • int_fast16_max int_fast16_min uint_fast16_max
  • int_fast32_max int_fast32_min uint_fast32_max
  • int_fast64_max int_fast64_min uint_fast64_max
  • INTMAX_MAX INTMAX_MIN UINTMAX_MAX

Note that all unsigned integer types have a minimum value of 0, so there is no corresponding macro.

Placeholders

C also defines placeholders for printf() and scanf() for the above types in the header file inttypes.h, see the chapter on inttypes.h.